package cn.apelx.shardingjdbc.domain;

import lombok.Getter;
import lombok.ToString;

import javax.persistence.*;
import java.io.Serializable;

/**
 * 订单明细
 *
 * @author apelx
 * @since 2022-05-13
 */
@ToString
@Getter
@Entity
@Table(name = "t_order_detail")
public class OrderDetail implements Serializable {

    @Id
    private Integer id;

    /**
     * 因为订单是根据这个字段分库的，冗余该字段，让订单明细下的数据与订单分到同一个库，不会跨库join
     */
    private Integer customerId;

    private String name;

    @ManyToOne
    @JoinColumn(name = "order_id")
    private Order order;

    protected OrderDetail() {
    }

    public OrderDetail(Integer id, Integer customerId, String name, Order order) {

        this.id = id;
        this.customerId = customerId;
        this.name = name;
        this.order = order;
    }
}
